Skip to content

Conversation

shuang886
Copy link

Given:

    Slider(value: $v1, in: 1...10, step: 2, onEditingChanged: { _ in })
    Text("Slider: \(v1)")
            
    ValueSlider(value: $v2, in: 1...10, step: 2, onEditingChanged: { _ in })
        .frame(height: 30)
    Text("ValueSlider: \(v2)")
Screenshot 2023-09-18 at 9 58 09 AM

Apple's Slider() reports the discrete values [ 1, 3, 5, 7, 9 ] while ValueSlider() reports [ 1, 2, 4, 6, 8, 10 ]. IOW, Slider()'s steps are offsets from the lowerBound while ValueSlider()'s are 0-based.

This PR changes the behavior of step to match Slider().

Note: even with this fix, ValueSlider() will report [ 1, 3, 5, 7, 9, 10 ] even though the upperBound value is not a multiple of step. That's easily worked around by client code if desired, so I'm not sure it should be fixed.

- i.e., lowerBound = 3.5, step = 0.2, values should be 3.7, 3.9, etc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant